package bounds.upper

object UpperBounds01 {
  def main(args: Array[String]): Unit = {
    val compareInt = new CompareInt(10, 20)
    println(compareInt.greater)
    //使用上界
    val commonCompare = new CommonCompare(Integer.valueOf(10), Integer.valueOf(50))
    println(commonCompare)
    val commonCompare2 = new CommonCompare(String.valueOf("hello"), String.valueOf("world"))
    println(commonCompare2)
  }

}

class CompareInt(n1: Int, n2: Int) {
  def greater = if (n1 > n2) n1 else n2
}

//使用上界
//说明
class CommonCompare[T <: Comparable[T]](ob1: T, ob2: T) {
  def greater = if (ob1.compareTo(ob2) > 0) ob1 else ob2
}